package com.jlhlyby.basics;

/**
 * 单例模式
 */
public class SingleInstance {
    //double check模式
    static class SingleOne{
        private static volatile SingleOne instance;
        public static SingleOne getInstance() {
            if (instance == null){
                synchronized (SingleOne.class){
                    if (instance == null){
                        instance = new SingleOne();
                    }
                }
            }
            return instance;
        }
    }
    static class SingleTwo{
        private static class Holder{
            private static SingleTwo instance = new SingleTwo();
        }
    }

}
